import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.math.BigDecimal;

public class PointOfSaleTerminalTest {
    public static final String PRICING_PROPERTIES_PATH = "src/pricing.properties";
    PointOfSaleTerminal terminal;

    @Before
    public void setUp() throws Exception {
        terminal = new PointOfSaleTerminal();
        terminal.setPricing(PRICING_PROPERTIES_PATH);
    }

    @Test
    public void testFirstCase() throws Exception {
        terminal.scan('A');
        terminal.scan('B');
        terminal.scan('C');
        terminal.scan('D');
        terminal.scan('A');
        terminal.scan('B');
        terminal.scan('A');
        BigDecimal result = terminal.calculateTotal();
        Assert.assertEquals(BigDecimal.valueOf(13.25), result);
    }

    @Test
    public void testFirstCase2() throws Exception {
        terminal.scan("ABCDABA");
        BigDecimal result = terminal.calculateTotal();
        Assert.assertEquals(BigDecimal.valueOf(13.25), result);
    }

    @Test
    public void testSecondCase() throws Exception {
        for (int i = 0; i < 7; i++) {
            terminal.scan('C');
        }
        BigDecimal result = terminal.calculateTotal();
        Assert.assertEquals(BigDecimal.valueOf(6.00), result);
    }

    @Test
    public void testSecondCase2() throws Exception {
        terminal.scan("CCCCCCC");
        BigDecimal result = terminal.calculateTotal();
        Assert.assertEquals(BigDecimal.valueOf(6.00), result);
    }

    @Test
    public void testThirdCase() throws Exception {
        terminal.scan('A');
        terminal.scan('B');
        terminal.scan('C');
        terminal.scan('D');
        BigDecimal result = terminal.calculateTotal();
        Assert.assertEquals(BigDecimal.valueOf(7.25), result);
    }

    @Test
    public void testThirdCase2() throws Exception {
        terminal.scan("ABCD");
        BigDecimal result = terminal.calculateTotal();
        Assert.assertEquals(BigDecimal.valueOf(7.25), result);
    }
}
